ASP.NET Core 5 and React by Carl Rippon

ASP.NET Core 5 and React by Carl Rippon

Author:Carl Rippon
Language: eng
Format: epub
Publisher: Packt Publishing Pvt Ltd
Published: 2021-01-06T00:00:00+00:00


Creating a repository method to change a question

Let's create the PutQuestion method in DataRepository.cs to change a question. This is very similar to the PostQuestion method we have just implemented:

public QuestionGetSingleResponse PutQuestion(int questionId, QuestionPutRequest question)

{

using (var connection = new SqlConnection(_connectionString))

{

connection.Open();

connection.Execute(

@"EXEC dbo.Question_Put

@QuestionId = @QuestionId, @Title = @Title,

@Content = @Content",

new { QuestionId = questionId, question.Title,

question.Content }

);

return GetQuestion(questionId);

}

}

Notice that we are using the Dapper Execute method because we are simply executing a stored procedure and not returning anything.

We've created the SQL parameters from a model class called QuestionPutRequest and the questionId parameters that were passed into the method. Let's create the QuestionPutRequest class in the models folder:

public class QuestionPutRequest

{

public string Title { get; set; }

public string Content { get; set; }

}

That's another method implemented.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.